<template>
    <div class="proxy-index pd-v-24">
        <image class="cover_bg position-a" src="@/static/cover_bg.png" style="width:100%" mode="widthFix"></image>


        <u-navbar
            leftIcon=""
            bgColor="rgba(0,0,0,0)"
            title="首页"
        >
        </u-navbar>


        <view class="proxy-index__body mr-t-100 pd-t-96 position-r">
            <view class="data-preview border16 pd-b-24 overflow-h bg-white">
                <view class="data-preview__header  position-r">
                    <view class="data-preview__header-bg position-a full-w full-h"></view>
                      
                    <view class="data-preview__header-title pd-h-26 pd-v-24 font28 lh-40 bold flex flex-center position-r">
                      <image class="data_bg position-a full-w full-h" src="@/static/data_bg.png" mode="widthFix"></image>
                        数据概览
                    </view>
                      
                </view>
                  

                <view class="data-preview__body">
                    <view class="flex flex-center">
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                                ¥{{dataOverview.revenueStatistics || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                收益统计
                            </view>
                              
                        </view>
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                               ¥{{dataOverview.dailyEarnings || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                当天收益
                            </view>
                              
                        </view>
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                                 ¥{{dataOverview.yesterdayEarnings || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                昨天收益
                            </view>
                              
                        </view>
                          
                    </view>

                    <view class="flex flex-center mr-t-44">
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                                {{dataOverview.deviceStatistics || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                设备统计
                            </view>
                              
                        </view>
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                                {{dataOverview.orderStatistics || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                订单统计
                            </view>
                              
                        </view>
                        <view class="flex-1 flex flex-center flex-j-center flex-ver">
                            <view class="font36 lh-50 color-default bold">
                                {{dataOverview.merchantStatistics || 0}}
                            </view>
                            <view class="mr-t-2 font26 lh-36 color-info">
                                商户统计
                            </view>
                              
                        </view>
                          
                    </view>
                      
                </view>

            </view>

            <view class="data-preview border16 overflow-h bg-white mr-t-20">
                <view class="data-preview__body pd-h-24">
                    <view class="flex flex-center flex-wrap">
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="storeManage">
                            <image src="@/static/store_manage.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                门店管理
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="shopManage">
                            <image src="@/static/shop_manage.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                商户管理
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="order">
                            <image src="@/static/order_manage.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                订单管理
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="wallet">
                            <image src="@/static/wallet.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                我的钱包
                            </view>
                              
                        </view>

                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="partnerManage" v-if="store?.user.userInfo1?.roleType == '1'">
                            <image src="@/static/partner_manage.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                合作伙伴
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="deviceManage">
                            <image src="@/static/device_manage.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                设备管理
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="cashOutAudit">
                            <image src="@/static/cash_out.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                提现审核
                            </view>
                              
                        </view>
                        <view class="w25 mr-b-48 flex flex-center flex-j-center flex-ver" @click="pwdReset">
                            <image src="@/static/pwd_reset.png" style="width:48rpx;" mode="widthFix"></image>
                            <view class="mr-t-16 font26 lh-36 color-info">
                                修改密码
                            </view>
                              
                        </view>
                          
                    </view>

                
                      
                </view>
                  
            </view>

            <view class="mr-t-20" @click="callPhone">
              <image src="@/sub_proxy/static/2.gif" class="full-w" mode="widthFix"></image>  
            </view>
              
        </view>


        <view class="proxy-index__footer position-f full-w flex flex-center flex-j-center">
          <view class="font28 lh-40 color-note position-a" @click="logout">退出登录</view>
        </view>
          
    </div>
</template>

<script setup>



import { useStore } from '@/store/index.js';
import { getDataOverviewForAgent,agentGetUserInfo,getDataOverviewForPartner } from "@/api/proxy.js";


import { computed, ref, onMounted, reactive } from "vue";
import { onShow } from '@dcloudio/uni-app';

const store = useStore();

const dataOverview = ref({})

const userPermission = ref({})


onShow(() => {
    if(store?.user?.userInfo1.roleType == 1){
      
      getDataOverviewForAgent().then(res => {
          console.log(res)
          if(res.code == 200) {
              dataOverview.value = res.data
          }
      })
    } else if(store?.user?.userInfo1.roleType == 2){
      getDataOverviewForPartner().then(res => {
          console.log(res)
          if(res.code == 200) {
              dataOverview.value = res.data
          }
      })
    }

    agentGetUserInfo().then(res => {
        if(res.code == 200) {
            userPermission.value = res.data
        }
    })
})

const storeManage = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/storeManage/storeManage'
    })
}

const shopManage = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/shopManage/shopManage'
    })
}

const order = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/order/order'
    })
}

const wallet = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/wallet/wallet'
    })
}

const partnerManage = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/partnerManage/partnerManage'
    })
}

const deviceManage = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/deviceManage/deviceManage'
    })
}

const cashOutAudit = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/cashOutAudit/cashOutAudit'
    })
}

const pwdReset = () => {
    uni.navigateTo({
        url: '/sub_proxy/pages/pwdReset/pwdReset'
    })
}

const logout = () => {
    uni.showModal({
        title: '提示',
        content: '确定退出登录？',
        success: function (res) {
            if (res.confirm) {
                // uni.removeStorageSync('token');
                // uni.removeStorageSync('userInfo');
                store.common.SET_TABINDEX(0);
                uni.reLaunch({
                    url: '/pages/index/index'
                })
            }
       }
    })
}

const callPhone = () => { 
    uni.makePhoneCall({
        phoneNumber: store?.common?.platformInfo.platformCustomerServicePhone
    });
}


</script>

<style lang="scss" scoped>
.proxy-index {
    min-height:100vh;
    background: #F5F5F5;

    .w25 {
        width: 25%;
    }

    .cover_bg {
      left:0;
      top:0;
    }

    .proxy-index__body {
        .data-preview__header {
            
            .data-preview__header-bg {
                z-index: 1;
            }

            .data-preview__header-title {
                z-index: 2;
                color:#000;
                &::before {
                    content: '';
                    display: block;
                    width:4rpx;
                    height:22rpx;
                    background:#3AC981;
                    margin-right:22rpx;
                }

                .data_bg {
                  
                  left:0;
                  top:0;
                }
            }
        }

    }

    .proxy-index__footer {
      bottom:88rpx;
      left:0;
    }
}
</style>